package com.ericsson.eritask.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ericsson.eritask.dao.ValidateUser;
import com.ericsson.eritask.domain.User;

@Repository
public class ValidateUserImpl implements ValidateUser {


	@PersistenceContext
	EntityManager entityManager;

	
	@Transactional
	@Override
	public List<User> getUserDtls(String user_name , String password) {
		// TODO Auto-generated method stub
		//    database interaction for validate user goes here 
		List<User> userList = null;
		try{
			
		// user_name ="1234";	
		//password="sushanta";
		TypedQuery<User> query = entityManager.createQuery("select u from User u where u.userName = ?1 and u.password =?2",User.class );
	
		query.setParameter(1,user_name );
		query.setParameter(2,password );
		 userList = query.getResultList();
		 System.out.println("userList:"+userList.size());
	    if(userList!=null && userList.size()>0){
		for(User user:userList){
			System.out.println("signum:"+user.getSignum());
			//System.out.println("project_id from database:"+project_id);	
		}
	   }
	  
	}
	   catch(Exception e){
		   e.printStackTrace();
	   }
		   
		return userList;
	}

}
